package com.zlj.huanxin.utils;

import android.content.Context;
import android.content.SharedPreferences;

/****
 *
 * 描述 ：
 *
 * 创建 ：
 *
 * 日期 ：2021/4/13
 *
 */
public class PreferenceManager {

    public static final String PREFERENCE_NAME = "saveInfo";

    private static PreferenceManager mPreferenceManager;

    private static SharedPreferences mSharedPreferences;

    private static SharedPreferences.Editor mEditor;


    private PreferenceManager(Context context)
    {
        mSharedPreferences = context.getSharedPreferences(PREFERENCE_NAME,Context.MODE_PRIVATE);
    }

    public static synchronized void init(Context context)
    {
        if (mPreferenceManager == null) {
            mPreferenceManager = new PreferenceManager(context);
        }
    }

    public synchronized static PreferenceManager getInstance(){
        if (mPreferenceManager == null){
            throw new RuntimeException("管理工具没初始化！！");
        }
        return mPreferenceManager;
    }


    private static String SHARED_KEY_AUTO_LOGIN = "shared_key_auto_login";


    /**
     * 设置是否自动登录，只有登录成功，此值才能设置为true.
     *
     * @param autoLogin the auto login
     */
    public void setAutoLogin(boolean autoLogin){
        mEditor.putBoolean(SHARED_KEY_AUTO_LOGIN,autoLogin);
        mEditor.commit();
    }

    public boolean getAutoLogin(){
        return mSharedPreferences.getBoolean(SHARED_KEY_AUTO_LOGIN,false);
    }




}
